package com.ecy.quadratic.ui.activity;

import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

import com.ecy.quadratic.R;
import com.ecy.quadratic.fragment.helper.BottomTabHelper;
import com.ecy.quadratic.reader.base.BaseActivity;
import com.ecy.quadratic.reader.component.AppComponent;

import butterknife.Bind;

public class MainActivity extends BaseActivity {

    @Bind(android.R.id.tabhost)
    FragmentTabHost mTabHost;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    public void initToolBar() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void configViews() {
        initHost();
        initTab();
        mTabHost.onTabChanged(BottomTabHelper.getTabsTxt()[0]);
    }

    private void initTab() {
        String[] tabs = BottomTabHelper.getTabsTxt();
        for (int i = 0; i < tabs.length; i++) {
            //新建TabSpec  
            TabSpec tabSpec = mTabHost.newTabSpec(BottomTabHelper.getTabsTxt()[i]);
            //设置view  
            View view = LayoutInflater.from(this).inflate(R.layout.bottom_tab_item, null);
            ((TextView) view.findViewById(R.id.foot_tv)).setText(BottomTabHelper.getTabsTxt()[i]);
            ((ImageView) view.findViewById(R.id.foot_iv)).setImageResource(BottomTabHelper.getTabsImg()[i]);
            tabSpec.setIndicator(view);
            //加入TabSpec  
            mTabHost.addTab(tabSpec, BottomTabHelper.getFramgent()[i], null);
        }
    }

    /*** 
     * 初始化Host 
     */
    private void initHost() {
        mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        //调用setup方法 设置view  
        mTabHost.setup(this, getSupportFragmentManager(), R.id.main_framelayout);
        //去除分割线  
        mTabHost.getTabWidget().setDividerDrawable(null);
    }

}  